package com.starking.wxx.controller;

import com.alibaba.fastjson.JSON;
import com.starking.wxx.mybatis.dao.UserAuthEntityMapper;
import com.starking.wxx.mybatis.entity.UserAuthEntity;
import com.starking.wxx.thread.TestThread;
import com.starking.wxx.thread.ThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @描述: 线程测试controller
 * @文件名: ThreadTestController.java
 * @创建人: wangxinxin
 * @创建时间: 2018/10/30
 * @修改人: wangxinxin
 * @修改备注: <br/>
 * <p>
 */
@Controller
@RequestMapping("/thread")
public class ThreadTestController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ThreadTestController.class);
    @Resource
    private UserAuthEntityMapper authEntityMapper;

    @RequestMapping("/test")
    public void test(HttpServletResponse response) {
        LOGGER.info("test.......");
        try {
            response.getWriter().write("test...");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/addOne")
    public void runOneThread(HttpServletResponse response) throws IOException {
        for (int i = 0; i < 3; i++) {
            TestThread testThread = new TestThread();
            ThreadFactory.execute(testThread);
        }
        response.getWriter().write("test...");
    }


    @RequestMapping("/mybatis")
    public void mybatisTest() {
        UserAuthEntity userAuthEntity = authEntityMapper.selectByPrimaryKey(1L);
        LOGGER.info("userAuthEntity = {}", JSON.toJSONString(userAuthEntity));
    }

}
